/*
 * Copyright 2009 BioTeam Inc
 * 
 * Licensed under License GNU LESSER GENERAL PUBLIC LICENSE version 3.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.gnu.org/copyleft/lesser.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package net.bioteam.appweb.ws.client.program;

import java.lang.reflect.Method;

import junit.framework.TestCase;
import net.bioteam.appweb.TestConfig;
import net.bioteam.appweb.model.Program;
import net.bioteam.appweb.model.ProgramBuilder;
import net.bioteam.appweb.submit.ProgramValueBean;
import net.bioteam.appweb.user.User;
import net.bioteam.appweb.ws.WsClient;

public class BlastallTest extends TestCase
{

	public BlastallTest()
	{
		super();
	}

	public BlastallTest(String name)
	{
		super(name);
	}

	public WsClient client;

	protected void setUp() throws Exception
	{
		TestConfig.init();
		User user = new User();
		user.setName(TestConfig.username);
		user.setPassword(TestConfig.password);
		client = new WsClient(user, TestConfig.serviceURL, null);

	}

	public static void main(String args[]) throws Exception
	{
		/*
		 * BlastallTest test=new BlastallTest(); test.setUp();
		 * 
		 * Method[] mss=test.getClass().getMethods(); for (Method ms: mss) { if
		 * (ms.getName().startsWith("test")) { ms.invoke(test); //break; } }
		 */
		BlastallTest test = new BlastallTest("testBl2seq1");
		junit.textui.TestRunner.run(test);
		TestConfig.shutdown();
	}

	public void testBlastall() throws Exception
	{
		String program = "blastall";
		ProgramBuilder.cache.remove(program);
		Program p = ProgramBuilder.getProgram(program);
		ProgramValueBean bean = new ProgramValueBean(p);
		if (TestConfig.clusterid != null)
		{
			bean.setValue("_cluster", TestConfig.clusterid);
		}
		bean.setValue("blastall", "blastn");
		bean.setValue("query", "inputs/fasta_single.seq");
		bean.setValue("nucleotid_db", "vector");
		if (TestConfig.clusterid != null)
		{
			bean.setValue("_cluster", TestConfig.clusterid);
		}
		String[] ret = client.runProgram(bean);
		postJobProcess(ret);

	}

	public void testBl2seq() throws Exception
	{
		String program = "bl2seq";
		ProgramBuilder.cache.remove(program);
		Program p = ProgramBuilder.getProgram(program);
		ProgramValueBean bean = new ProgramValueBean(p);
		if (TestConfig.clusterid != null)
		{
			bean.setValue("_cluster", TestConfig.clusterid);
		}
		if (TestConfig.clusterid != null)
		{
			bean.setValue("_cluster", TestConfig.clusterid);
		}
		bean.setValue("bl2seq", "blastn");
		bean.setValue("first_sequence", "inputs/fasta_single.seq");
		bean.setValue("second_sequence", "inputs/fasta_single1.seq");
		String[] ret = client.runProgram(bean);
		postJobProcess(ret);

	}

	public void testBl2seq1() throws Exception
	{
		String program = "bl2seq";
		ProgramBuilder.cache.remove(program);
		Program p = ProgramBuilder.getProgram(program);
		ProgramValueBean bean = new ProgramValueBean(p);
		if (TestConfig.clusterid != null)
		{
			bean.setValue("_cluster", TestConfig.clusterid);
		}
		bean.setValue("bl2seq", "blastn");
		bean.setValue("first_sequence", "inputs/fasta_single.seq");
		bean.setValue("second_sequence", "inputs/fasta_single1.seq");
		String[] ret = client.runProgram1(bean);
		postJobProcess(ret);

	}

	public void testBatchblast() throws Exception
	{
		String program = "batchblast";
		ProgramBuilder.cache.remove(program);
		Program p = ProgramBuilder.getProgram(program);
		ProgramValueBean bean = new ProgramValueBean(p);
		if (TestConfig.clusterid != null)
		{
			bean.setValue("_cluster", TestConfig.clusterid);
		}
		bean.setValue("nlastall", "blastn");
		bean.setValue("query", "inputs/fasta_six.seq");
		bean.setValue("nucleotid_db", "vector");
		String[] ret = client.runProgram(bean);
		postJobProcess(ret);

	}

	protected void postJobProcess(String ret[])
	{
		String jobid = ret[0];
		TestConfig.logger.info("job id is " + jobid);
		TestConfig.logger.info("cmdline is " + ret[2]);
	}

}
